/* eslint-disable no-empty-pattern */
import { api_add, api_delById, api_modifyAll, api_queryById } from '@/api/crud'
import { api_addBatch, api_patchByParams, api_checkLabel, api_listAll, api_getConfigUl } from '@/api/sys_config'

const pathName = 'config'

const state = {}

const mutations = {}

const actions = {
  // 添加
  add({}, sysConfig) {
    return new Promise((resolve, reject) => {
      api_add(pathName, sysConfig)
        .then((response) => {
          resolve(response)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 批量添加系统设置
  addBatch({}, paramsJson) {
    return new Promise((resolve, reject) => {
      api_addBatch(paramsJson)
        .then((response) => {
          resolve(response)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 删除
  delById({}, id) {
    return new Promise((resolve, reject) => {
      api_delById(pathName, id)
        .then((response) => {
          resolve(response)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 修改
  modifyAll({}, sysConfig) {
    return new Promise((resolve, reject) => {
      api_modifyAll(pathName, sysConfig)
        .then((response) => {
          resolve(response)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  patchByParams({}, paramsJson) {
    return new Promise((resolve, reject) => {
      api_patchByParams(paramsJson)
        .then((response) => {
          resolve(response)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 根据id查询到一个对象全部资料
  queryById({}, id) {
    return new Promise((resolve, reject) => {
      api_queryById(pathName, id)
        .then((response) => {
          resolve(response.data.data)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 添加系统设置时要先看看系统设置名是否已经用过
  checkLabel({}, paramsJson) {
    return new Promise((resolve, reject) => {
      api_checkLabel(paramsJson)
        .then((response) => {
          resolve(response.data.data)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 得到某标签下所有系统设置
  listAll({}, tag) {
    return new Promise((resolve, reject) => {
      api_listAll(tag)
        .then((response) => {
          resolve(response.data.data)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 得到所有上传文件的系统设置
  getConfigUl({}) {
    return new Promise((resolve, reject) => {
      api_getConfigUl()
        .then((response) => {
          resolve(response.data.data)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
}
